<!DOCTYPE HTML>
<html>

	<head>
		<meta charset="UTF-8">
		<title>LingPowerAI</title>
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		 <link rel="stylesheet" href="../../css/h5">
		 		 <script src="../../js/H5+.js"></script>
		<script type="text/javascript">
			document.write('<script src="../../js/fix.js?rd=?rd=' + Math.random() + '"><\/script>');
		</script>
		<script type="text/javascript">
			link();
		</script>
		<script type="text/javascript">
		script();
	</script>
	</head>
	

	<body>

	<header id="header" class="mui-bar mui-bar-nav">
		<a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
			<h1 class="mui-title" id="title">详情</h1>
		<a href="javascript:;" onclick="aretcleShare()" class="mui-icon mui-icon-redo mui-pull-right"></a>
	</header>
		<div class="mui-content"></div>
		<script>
			mui.init();
	
			var ws=null,embed=null;
			// 扩展API加载完毕，现在可以正常调用扩展API 
			function plusReady(){
				ws=plus.webview.currentWebview();
				ws.setStyle({
					scrollIndicator:"none"
				})
				updateSerivces();
				setTimeout(createEmbed, 500);	//延迟创建子窗口避免影响窗口动画
			}
	
			// 判断扩展API是否准备，否则监听plusready事件
			if(window.plus){
				plusReady();
			}else{
				document.addEventListener('plusready', plusReady, false);
			}
			// 创建子Webview
			function createEmbed(url){
				var self = plus.webview.currentWebview();
				var link = self.link;
				var url=link;
				var topoffset='44px';
				embed=plus.webview.create(url,'embed',{top:topoffset,bottom:'0px',position:'dock',dock:'bottom',bounce:'vertical'});
				ws.append(embed);
				
				embed.setStyle({
					scrollIndicator:"none"
				})
			}

		

			var shares=null;
			var sweixin=null;
			var buttons=[
			  {title:'微信好友',extra:{scene:'WXSceneSession'}},
			  {title:'微信朋友圈',extra:{scene:'WXSceneTimeline'}},
			  {title:'微信收藏',extra:{scene:'WXSceneFavorite'}}
			];
				
			/**
			 * 更新分享服务
			 */
			function updateSerivces(){
				plus.share.getServices(function(s){
					shares={};
					for(var i in s){
						var t=s[i];
						shares[t.id]=t;
					}
			    sweixin=shares['weixin'];
				}, function(e){
					outSet('获取分享服务列表失败：'+e.message);
				});
			}
			
			// 分享网页
			function aretcleShare(){
					var self = plus.webview.currentWebview();
					var link = self.link;
					var title = self.title;
					var content= self.content;
					var url=link;
			  var msg={type:'web',thumbs:['../../images/logo.png']};
				  msg.href=url;
				  msg.title=title;
				msg.content=content==""?title:content;
				sweixin?plus.nativeUI.actionSheet({title:'分享给朋友',cancel:'取消',buttons:buttons}, function(e){
			  	(e.index>0)&&share(sweixin, msg, buttons[e.index-1]);
			  }):plus.nativeUI.alert('当前环境不支持微信分享操作!'); 
			}
			
			// 执行分享
			function share(srv, msg, button){
				outSet('分享操作：');
			  if(!srv){
			    outLine('无效的分享服务！');
			    return;
			  }
			  button&&(msg.extra=button.extra);
				// 发送分享
				if(srv.authenticated){
					outLine('---已授权---');
					doShare(srv, msg);
				}else{
					outLine('---未授权---');
					srv.authorize(function(){
						doShare(srv, msg);
					}, function(e){
						outLine('认证授权失败：'+JSON.stringify(e));
					});
				}  
			}
			// 发送分享
			function doShare(srv, msg){
				outLine(JSON.stringify(msg));
				srv.send(msg, function(){
					outLine('分享到"'+srv.description+'"成功！');
				}, function(e){
					outLine('分享到"'+srv.description+'"失败: '+JSON.stringify(e));
				});
			}
			// 解除授权
			function cancelAuth(){
				outSet('解除授权：');
			  if(sweixin){
			    if(sweixin.authenticated){
			    	outLine('取消"'+sweixin.description+'"');
			    }
			    sweixin.forbid();
			  }else{
			    outLine('当前环境不支持微信分享操作!');
			  }
			}
	

		</script>
			<div id="outpos"/ style="display: none;"></div>
			<div id="output" style="display: none;"></div>
	</body>

</html>
